// ValidationAspects
// Written by Mike Saunders
// Released under Microsoft Public License (Ms-PL)
using System;
using NUnit.Framework;
using ValidationAspects;
using ValidationAspects.Factories;
using ValidationAspects.PostSharp;
using ValidationAspects.Sdk;

namespace TestValidationAspects.PostSharp
{
	[TestFixture]
	public class TestValidateAttribute
	{
		[Test]
		public void Test_default_get_AspectPriority()
		{
			Assert.AreEqual(0, new ValidateAttribute().AspectPriority);
		}

		[Test]
		public void Test_default_get_ValidateAllProperties()
		{
			Assert.IsFalse(new ValidateAttribute().AttributedPropertiesOnly);
		}

		[Test]
		public void Test_default_get_ValidateAllMethods()
		{
			Assert.IsFalse(new ValidateAttribute().AttributedMethodsOnly);
		}

		#region Test Validator Attribute declaration
		[Test]
		[ExpectedException(typeof(ValidationException))]
		public void Test_ProvideAspects_throws_for_invalid_validation_decoration_property()
		{
			new ValidateAttribute().ProvideAspects(typeof(InvalidValidatorDecorationProperty), null);
		}

		[Test]
		[ExpectedException(typeof(ValidationException))]
		public void Test_ProvideAspects_throws_for_invalid_validation_decoration_method()
		{
			new ValidateAttribute().ProvideAspects(typeof(InvalidValidatorDecorationMethod), null);
		}

		[Test]
		[ExpectedException(typeof(ValidationException))]
		public void Test_ProvideAspects_throws_for_invalid_validation_decoration_parameter()
		{
			new ValidateAttribute().ProvideAspects(typeof(InvalidValidatorDecorationParameter), null);
		}
		#endregion

		#region Mocks
		[AttributeUsage(AttributeTargets.Property | AttributeTargets.Parameter | AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
		public class SpecificTypeValidatorAttribute : ValidatorAttribute
		{
			#region Overrides of ValidatorAttribute
			public override IValidatorFactory Factory
			{
				get { return new LessThan(); }
			}
			#endregion
		}

		public class InvalidValidatorDecorationMethod
		{
			[SpecificTypeValidator]
			public void DoIt() {}
		}

		public class InvalidValidatorDecorationParameter
		{
			public void DoIt([LessThan(100)] string s) {}
		}

		public class InvalidValidatorDecorationProperty
		{
			[NotEqual(123.456)]
			public string Property { get; set; }
		}
		#endregion
	}
}